package com.wanxi.servlet.deviceclass;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.VO.DeviceClassVO;
import com.wanxi.VO.UserVO;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.DeviceClassService;
import com.wanxi.service.UserService;
import com.wanxi.service.impl.DeviceClassServiceImpl;
import com.wanxi.service.impl.UserServiceImpl;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * 菜系
 * @Author : 林子淳
 * @create 2023/2/28 9:02
 */
//@WebServlet("/back/device_class/findAll")
public class DeviceClassFindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //2、获取前端传递后端的值
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String name = req.getParameter("name");
        String enable = req.getParameter("enable");
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");
        //3.封装VO数据
        DeviceClassVO deviceClassVO = new DeviceClassVO();
        deviceClassVO.setStartTime(Tool.nullToStr(start));
        deviceClassVO.setEndTime(Tool.nullToStr(end));
        deviceClassVO.setName(Tool.nullToStr(name));
        deviceClassVO.setEnable(Tool.strToInt(enable));
        deviceClassVO.setPage(Tool.strToPage(page));
        deviceClassVO.setLimit(Tool.strToLimit(limit));
        System.out.println("进入的了页面/device_class/findAll："+deviceClassVO.toString());
        //4.调用服务逻辑层
        DeviceClassService deviceClassService = new DeviceClassServiceImpl();
        //5.得到返回的结果
//        ResultDTO resultDTO = null;
        ResultDTO resultDTO = deviceClassService.findAll(deviceClassVO);
        System.out.println("返回的值/device_class/findAll："+deviceClassVO.toString());
        //        6.返回给前端
        resp.getWriter().println(JSONObject.toJSONString(resultDTO));
    }
}
